package pro.softzhang.algo.lc2100;

import pro.softzhang.algo.common.ListNode;
import pro.softzhang.algo.flag.difficulty.DYellow;

@DYellow
public class LC2181_MergeNodesInBetweenZeros {

    static class Solution {
        public ListNode mergeNodes(ListNode head) {
            ListNode dummy = new ListNode(-1, new ListNode()), p = dummy;
            int sum = 0;
            head = head.next;
            while (head != null) {
                if (head.val != 0) {
                    sum += head.val;
                } else {
                    p.next = new ListNode(sum, null);
                    p = p.next;
                    sum = 0;
                }
                head = head.next;
            }
            return dummy.next;
        }
    }
}
